//
//  baseErrorCodeHandler.m
//  baseVC
//
//  Created by 陶磊 on 2019/12/16.
//  Copyright © 2019 QHT. All rights reserved.
//

#import "baseErrorCodeHandler.h"


typedef NS_ENUM(NSInteger, CLCWErrorCode){
    BASENOUSER          = 100009, //用户不存在
    BASENOLOGIN         = 100, //未登录
    BASELOGINTIMEOUT    = 100017, // 失效
    BASELOGINEXIT       = 100020, //其他设备登陆
    BASEREQUESTILLEGAL  = 100067, //登录失效
};

@implementation baseErrorCodeHandler

- (void)handlerErrorCode:(NSInteger)code msg:(NSString *)msg {
    switch (code) {
        case BASENOUSER:
        case BASENOLOGIN:
        case BASELOGINTIMEOUT:
        case BASELOGINEXIT:
        case BASEREQUESTILLEGAL:
       {
            //退出登录重新登录
            [self quitAndRelogin:code msg:msg];
            break;
        }
        default://输出错误
            break;
    }
}

- (void)quitAndRelogin:(NSInteger)code msg:(NSString *)msg
{
    //删除登录态
//    [ZHUUSERDEFAULT setBool:NO forKey:ZHUIsLogin];
//    [ZHUUSERDEFAULT removeObjectForKey:ZHUToken];
//    [ZHUUSERDEFAULT removeObjectForKey:ZHUUserName];

//
//    //跳转到登陆界面
//    ZHULoginVC * loginVC = [CLCWCommonMethod instantiateVCWithName:ZHULoginStoryboard ID:@"ZHULoginNavi"];
//    [KEYWINDOW.rootViewController presentViewController:loginVC animated:YES completion:nil];

//    UIViewController *rootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
//    if ([rootVC isKindOfClass:[CLCWRootTabBarVC class]])
//    {
//        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:msg preferredStyle:UIAlertControllerStyleAlert];
//        UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action)
//        {
//            //退出设置根视图 到登录页
//            CLCWLoginVC *loginController = [[CLCWLoginVC alloc]init];
//            UIWindow *keyWindow = [[UIApplication sharedApplication]keyWindow];
//            keyWindow.rootViewController = nil;
//            keyWindow.rootViewController = [[CLCWNavigationVC alloc]initWithRootViewController: loginController];
//        }];
//
//        [alertController addAction:okAction];
//        [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:alertController animated:YES completion:nil];
//    }
}






@end
